u8 cal_setup(u8 flag){
u8 modetmp,tmptchk;
dataout[0]=0x21;
tmptchk=tchkmode;
tchkmode=0;
modetmp=rezhim;
tchk=0; tchk|=0b010000000000;
if(calvector=x1){
	tchk|=0b1000;								//   "-"
}
//  4  3 
tchk|=0b100;
while(flag==1){
if (!(butup&&butdown)){	
	switch(dataout[0]){
	case 0x21:
		hourcal=calsetpart2(hourcal);
	break;
	case 0x22:
		daycal=calsetpart2(daycal);
	break;
	case 0x23:
		monthcal==calsetpart2(monthcal);
	break;
	}
	} else{
		if(!butleft){
			dataout[0]--;
			if(dataout[0]<0x21)
				flag=0;
		}
		if(!butright){
			dataout[0]++;
			if(dataout[0]>0x23)
				flag=0;
		}
		if(!butok){
			flag=0;
	}
	}	
	while(anybut){
	delay(100);
	}
}
eep_write(monthcal_addr,monthcal);
eep_write(daycal_addr,daycal);
pcf_write_addr(hourcal,hourcal_addr);
tchkmode=tmptchk;
rezhim=modetmp;
}

u8 calsetpart2 (u8 cal){
		if(!butup){
			if (calvector==0){
				cal++;
			}
			else{
				cal--;
				if(cal==0){
					calvector=0;
					tchk&=(~(1<<3));							//   "-"
				}	
			}
		}
		if(!butdown){
			if (calvector==0){
				if(cal==0){
					calvector=x1;
					cal++;
					tchk|=0b1000;								//   "-"
				}
				else{
					cal--;
				}
			}
			else{
				cal++;	
			}
		}
		return cal;
}